public class TestZJ {


    public static void main(String[] args) {

        String str1 = "ab";

        String str2 = "ddgabchhh";

        System.out.println(findStringIndex(str1, str2));


    }

    public static int findStringIndex(String str1, String str2){

        if (str1.length() > str2.length()){
            return -1;
        }
        int index = 0;
        String mid = "";
        int length = str1.length();
        char[] charArray2 = str2.toCharArray();
        for (int i = 0 ; i < charArray2.length; i++){
           mid += String.valueOf(charArray2[i]);
           if(mid.length() == length){
               if (mid.equals(str1)){
                   return index;
               }
               i = index;
               index++;
               mid = "";
           }
        }
        return -1;
    }

}
